package cn.achao.csr.api.model.entity;

import java.util.Date;
import java.io.Serializable;

import cn.achao.csr.api.model.enums.HotFlagEnum;
import cn.achao.csr.api.model.enums.RoomTypeEnum;
import cn.achao.csr.base.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * (ChatRoom)实体类
 *
 * @author achao
 * @since 2025-02-06 21:42:42
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ChatRoom extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 212318176911543595L;

    /**
     * 主键
     */
    @TableId(type = IdType.ASSIGN_ID)
    private Long id = super.getId();
    /**
     * 是否热点房间
     */
    private Integer hotFlag;
    /**
     * 房间类型
     */
    private Integer roomType;
    /**
     * 会话中的最后一条消息id
     */
    private Long lastMsgId;
    /**
     * 会话最后消息的更新时间
     */
    private Date activeTime;
    /**
     * 额外信息（根据不同类型房间有不同存储的东西）
     */
    private String extJson;
    /**
     * 房间状态
     */
    private String status;
    /**
     * 创建者
     */
    private String createBy;
    /**
     * 更新者
     */
    private String updateBy;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 更新时间
     */
    private Date updateTime;
    /**
     * 是否删除
     */
    private Boolean isDel;
    /**
     * 备注
     */
    private String remark;

    /**
     * INSERT INTO `csr`.`leaf_alloc` (`biz_tag`, `max_id`, `step`, `description`)
     * VALUES ('seq_chat_room', 1, 100, 'ChatRoom主键');
     * @return
     */
    @Override
    public String sequenceCode() {
        return "seq_chat_room";
    }
    
    public ChatRoom(Boolean generateId) {
        super(generateId);
    }

    @JsonIgnore
    public boolean isHotRoom() {
        return HotFlagEnum.of(this.hotFlag) == HotFlagEnum.YES;
    }

    @JsonIgnore
    public boolean isRoomFriend() {
        return RoomTypeEnum.of(this.roomType) == RoomTypeEnum.FRIEND;
    }

    @JsonIgnore
    public boolean isRoomGroup() {
        return RoomTypeEnum.of(this.roomType) == RoomTypeEnum.GROUP;
    }
}

